var successUpdateCallback = function (data) {
    var tip = '';
    switch (data.status) {
        case 200:
            tip = '更新成功';
            tooltipWrong($('#requestEdit'), tip, 3);
            window.setTimeout(function () {
                $('#requestCannel').click();
                window.location.reload();
            }, 1000);
            break;
    }
    tooltipWrong($('#requestConfuse'), tip, 2);
};
var errorUpdateCallback = function (data) {
    if (typeof (data.responseJSON) == "undefined") {
        tooltipWrong($('#requestConfuse'), '系统内部错误', 3);
    } else {
        tip = data.responseJSON.info;
        tooltipWrong($('#requestConfuse'), tip, 3);
    }
};

$(function () {

    $("input[id='requestEditEnddate']").datepicker({
        format: 'yyyy-mm-dd',
        language: "zh-CN",
        autoclose: true
    });

    $(".edit").on('click', function (e) {
        e.preventDefault();
        var obj = JSON.parse(($(this).attr("data-json")));
        $("#requestEditHotel").val(obj.name);
        $("#requestEdit").attr("data-value", obj.id);
        $("#requestEditEnddate").val(obj.enddate);
        if( obj.usage==1 ){
            $('#requestEditStatus_kaitong').attr("checked",true);
        }else if( obj.usage==2 ){
            $('#requestEditStatus_shiyong').attr("checked",true);
        }else if( obj.usage==3 ){
            $('#requestEditStatus_test').attr("checked",true);
        }else if( obj.usage==4 ){
            $('#requestEditStatus_free').attr("checked",true);
        }
        $('#requestEditRoomLimit .roomlimit').prop("selected",false);
        $('#requestEditRoomLimit .nolimit').prop("selected",false);
        if (obj.roomlimit == 0) {
            $('#requestEditRoomLimit .nolimit').prop("selected",true);
        } else {
            $('#requestEditRoomLimit .roomlimit').prop("selected",true);
        }
    });


    //确认修改
    $("#requestEdit").on("click", function (e) {
        e.preventDefault();
        //检查参数
        var params = new Object();
        params.id = $(this).attr("data-value");
        params.enddate = $("#requestEditEnddate").val();
        params.usage = $('input:radio[name="requestEditStatus"]:checked').val();
        params.roomlimit = $("#requestEditRoomLimit").val();
        if(params.enddate==''){
            tooltipWrong($('#requestEditEnddate'), "到期时间不能为空", 3);
            return;
        }
        ajaxRequest('/Home/Hotel/setDate', params, 'post', successUpdateCallback, errorUpdateCallback);

    });


});
